<?php
include_once('lib/config.php');
include_once('lib/Db.class.php');
include_once('lib/Model.class.php');
include_once('lib/Upyun.class.php');
include_once('lib/function.php');

$redis = new Redis();
$redis->connect("23.88.238.143","6379");  //php客户端设置的ip及端口
if(!$redis) die('redis connect fail');

$model = new Model;
$localDir = dirname(__FILE__).'/Public';

$limit = 5000;
while($limit--) {
  $stop = $redis->get('LNPAN_QUEUE_STOP');
  if($stop) {
    die('stop');
  }

  $list = $model->query('select id,format_url from ring_news_format where state=1 order by id desc limit 20');
  foreach ($list as $item) {
    $parse = parse_url($item['format_url']);
    $filepath = $localDir.$parse['path'];
    if(file_exists($filepath)) {
      $model->query("update ring_news_format set state=2 where id='".$item['id']."'");
      $redis->sAdd(KEY_QUEUE_LOCAL_UPDATE_SUCCESS, date('Y-m-d H:i:s').':'.$item['id'].':'.$filepath);
    } else {
      $redis->sAdd(KEY_QUEUE_LOCAL_UPDATE_WAIT, $item['id'].':'.$item['format_url']);
    }
  }

  //print_r($list);
  //die('end');

  if(empty($list)) {
    echo "update empty\n";
    sleep(1);
  }
}